<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of soaUsers
 *
 * @author dxx
 */

namespace app\common\model\oms;

use think\Model;

class StaffStore extends Model {

    protected $table = 'staff_store';
    protected $connection = ['database' => 'oms'];

    
    /**
     * 通过条件获取职员门店关系表
     * @param type $condition
     * @param type $field
     * @return type
     */
    public function getStaffStoreByCondition($condition,$field='*'){
        return $this->where($condition)->field($field)->find();
    }
    
    //根据staff_id查找store_id
    public function get_store_id($staff_id) {
        return $this->field('store_id')->where(['staff_id'=>$staff_id,'is_current'=>'1'])->find()['store_id'];
    }
    
    //查找门店店员信息
    public function get_staff_info_by_store_id($store_id,$company_code) {   
       $data = $this->join('oms.staffs staff','staff_store.staff_id = staff.staff_id','left')
                    ->field('staff.avatar,staff.price,staff.staff_name,staff.star,staff.introduction,staff.staff_id,staff.reserve_status,staff.void_schedule_sum')
                    ->where(['staff_store.store_id'=>$store_id,'staff.is_delete'=>'0','reserve_status'=>'1','staff_status'=>'1','company_code'=>$company_code])
                    ->select();
       return $data;
    }
}
